package center.leon.zootokenserversentinel.runner;

import com.alibaba.csp.sentinel.cluster.server.ClusterTokenServer;
import com.alibaba.csp.sentinel.cluster.server.SentinelDefaultTokenServer;
import com.alibaba.csp.sentinel.cluster.server.config.ClusterServerConfigManager;
import com.alibaba.csp.sentinel.cluster.server.config.ServerTransportConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * @author : Leon on XXM Mac
 * @since : create in 2024/8/22 16:36
 */
@Slf4j
@Component
public class StartTokenServerRunner implements ApplicationRunner {

//    static {//使用系统属性代替启动参数
//        // 控制台地址
//        System.setProperty("csp.sentinel.dashboard.server", "localhost:8080");
//        // sentinel端口
//        System.setProperty("csp.sentinel.api.port", "8719");
//        // 服务名称
//        System.setProperty("project.name", "token-server");
//        // 设置pid(可选)
//        System.setProperty("csp.sentinel.log.use.pid", "true");
//    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        ClusterTokenServer tokenServer = new SentinelDefaultTokenServer();
        ClusterServerConfigManager.loadGlobalTransportConfig(new ServerTransportConfig());
        tokenServer.start();
    }
}
